from PySide2.QtWidgets import QApplication, QMainWindow, QTableWidget, QTableWidgetItem
from PySide2.QtCore import Qt
from .params_table import ParamsTable

class LazyTable(ParamsTable):
    
    def __init__(self, rows=0, columns=2, isLibrary=False, parent=None):
        super(LazyTable, self).__init__(rows=rows, columns=columns, parent=parent)
        self.data = []
        self.displayed_data = []
        self.verticalScrollBar().valueChanged.connect(self.on_scroll)
        
    def on_scroll(self):
        current_row = self.verticalScrollBar().value()
        if current_row >= len(self.displayed_data) - 20:
            self.load_more_data()
            
    def load_more_data(self):
        start = len(self.displayed_data)
        end = start + 20
        for row_data in self.data[start:end]:
            self.addRow(row_data)
            